#!/bin/bash
########## cffr investment  测试版本部署脚本 
date_stamp=`date "+%Y-%m-%d %H:%M:%S"`
date1=`date "+%Y-%m-%d-%H-%M-%S"`
echo "123+123" 
#jar地址
SERVCER_JAR=earning-farm-investment-0.0.1-SNAPSHOT.jar
#日志名称
LOG_NAME=cff-investment.log
#进入对应目录
DIR="/home/ubuntu/cff-investment"
#输出信息
echo '---------------------------------------'
echo $DIR
#创建项目jar包工程目录
if [ ! -d $DIR/jar ];then
  mkdir -p $DIR/jar
fi
#创建备份目录
echo $date_stamp
#杀死java进程
_pid=`ps -ef | grep java | grep jar/$SERVCER_JAR |awk '{print $2}'`
echo "kill ------>"$SERVCER_JAR "pid---->" $_pid
[ -n "$_pid" ] && kill -9 $_pid
_pid1=`ps -ef | grep java | grep jar1/$SERVCER_JAR |awk '{print $2}'`
echo "kill ------>"$SERVCER_JAR "pid---->" $_pid
[ -n "$_pid1" ] && kill -9 $_pid1
_pid2=`ps -ef | grep java | grep jar2/$SERVCER_JAR |awk '{print $2}'`
echo "kill ------>"$SERVCER_JAR "pid---->" $_pid
[ -n "$_pid2" ] && kill -9 $_pid2

_pid3=`ps -ef | grep java | grep jar3/$SERVCER_JAR |awk '{print $2}'`
echo "kill ------>"$SERVCER_JAR "pid---->" $_pid
[ -n "$_pid2" ] && kill -9 $_pid3

_pid4=`ps -ef | grep java | grep jar4/$SERVCER_JAR |awk '{print $2}'`
echo "kill ------>"$SERVCER_JAR "pid---->" $_pid
[ -n "$_pid4" ] && kill -9 $_pid4

_pid5=`ps -ef | grep java | grep jar5/$SERVCER_JAR |awk '{print $2}'`
echo "kill ------>"$SERVCER_JAR "pid---->" $_pid
[ -n "$_pid5" ] && kill -9 $_pid5

echo $SERVCER_JAR
cp $DIR/$SERVCER_JAR  $DIR/jar
cp $DIR/$SERVCER_JAR  $DIR/jar1
cp $DIR/$SERVCER_JAR  $DIR/jar2

cp $DIR/$SERVCER_JAR  $DIR/jar3
cp $DIR/$SERVCER_JAR  $DIR/jar4
cp $DIR/$SERVCER_JAR  $DIR/jar5
branch_v=$1
export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_311
export JAVA=$JAVA_HOME/bin/java
export PATH=${JAVA_HOME}/bin:$PATH

echo '---------------------------------------java path'
source /home/ubuntu/cff-investment/.env
nohup  java -jar \
          -Xms512m -Xmx512m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC \
          -Xloggc:$DIR/logs/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps \
          -Dspring.profiles.active="prod" \
	  -Dserver.port=8280 \
          -Dvalue_type=1 \
	  -Dserver.servlet.context-path=/husdc \
          -Dspring.datasource.username=$investment_name -Dspring.datasource.password=$investment_passwd \
          -Dspring.datasource.url="jdbc:mysql://172.31.40.23:3307/earningfarm?useUnicode=true&characterEncoding=utf-8" \
          -Dlogging.file.path=$DIR \
          -Dserver.address=172.31.40.23 \
          $DIR/jar/$SERVCER_JAR  >>$DIR/logs/$LOG_NAME  2>&1  &
sleep 5
nohup  java -jar \
          -Xms512m -Xmx512m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC \
          -Xloggc:$DIR/logs1/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps \
          -Dspring.profiles.active="prod" \
          -Dserver.port=8380 \
          -Dspring.datasource.username=$investment_name_1 -Dspring.datasource.password=$investment_passwd_1 \
	  -Drisk_type=0   \
	  -Dserver.servlet.context-path=/usdc \
          -Dspring.datasource.url="jdbc:mysql://172.31.40.23:3307/earningfarm_1?useUnicode=true&characterEncoding=utf-8" \
          -Dlogging.file.path=/home/ubuntu/cff-investment/logs/usdc/  \
          -Dserver.address=172.31.40.23 \
          $DIR/jar1/$SERVCER_JAR  >>$DIR/logs/usdc/$LOG_NAME  2>&1  &

sleep 5
nohup  java -jar \
          -Xms512m -Xmx512m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC \
          -Xloggc:$DIR/logs2/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps \
          -Dspring.profiles.active="prod" \
	  -Dcff_name=ETH \
          -Dserver.port=8580 \
          -Dspring.datasource.username=$investment_name_2 -Dspring.datasource.password=$investment_passwd_2 \
          -Drisk_type=1   \
          -Dserver.servlet.context-path=/heth \
          -Dspring.datasource.url="jdbc:mysql://172.31.40.23:3307/earningfarm_heth?useUnicode=true&characterEncoding=utf-8" \
          -Dlogging.file.path=/home/ubuntu/cff-investment/logs/heth  \
          -Dserver.address=172.31.40.23 \
          $DIR/jar2/$SERVCER_JAR  >>$DIR/logs/heth/$LOG_NAME  2>&1  &

sleep 5
echo "musdc"
nohup  java -jar \
          -Xms512m -Xmx512m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC \
          -Xloggc:$DIR/logs/musdc/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps \
          -Dspring.profiles.active="prod" \
          -Dcff_name=USDC \
          -Dserver.port=8680 \
          -Dspring.datasource.username=$investment_name -Dspring.datasource.password=$investment_passwd \
          -Drisk_type=0   \
          -Dserver.servlet.context-path=/musdc \
          -Dnet_work=mainnet  \
          -Dspring.datasource.url="jdbc:mysql://172.31.40.23:3307/earningfarm_musdc?useUnicode=true&characterEncoding=utf-8" \
          -Dlogging.file.path=/home/ubuntu/cff-investment/logs/musdc  \
          -Dserver.address=172.31.40.23 \
          $DIR/jar3/$SERVCER_JAR  >>$DIR/logs/musdc/$LOG_NAME  2>&1  &

sleep 5
echo "metch"
nohup  java -jar \
          -Xms512m -Xmx512m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC \
          -Xloggc:$DIR/logs/meth/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps \
          -Dspring.profiles.active="prod" \
          -Dcff_name=ETH \
          -Dserver.port=8780 \
          -Dspring.datasource.username=$investment_name -Dspring.datasource.password=$investment_passwd \
          -Drisk_type=0   \
          -Dserver.servlet.context-path=/meth \
          -Dnet_work=mainnet \
          -Dspring.datasource.url="jdbc:mysql://172.31.40.23:3307/earningfarm_meth?useUnicode=true&characterEncoding=utf-8" \
          -Dlogging.file.path=/home/ubuntu/cff-investment/logs/meth  \
          -Dserver.address=172.31.40.23 \
          $DIR/jar4/$SERVCER_JAR  >>$DIR/logs/meth/$LOG_NAME  2>&1  &

sleep 5
echo "mwbtc"
nohup  java -jar \
          -Xms512m -Xmx512m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC \
          -Xloggc:$DIR/logs/wbtc/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps \
          -Dspring.profiles.active="prod" \
          -Dcff_name=WBTC \
          -Dserver.port=8880 \
          -Dspring.datasource.username=$investment_name -Dspring.datasource.password=$investment_passwd \
          -Drisk_type=0   \
          -Dserver.servlet.context-path=/mwbtc \
          -Dnet_work=mainnet  \
          -Dspring.datasource.url="jdbc:mysql://172.31.40.23:3307/earningfarm_mwbtc?useUnicode=true&characterEncoding=utf-8" \
          -Dlogging.file.path=/home/ubuntu/cff-investment/logs/wbtc  \
          -Dserver.address=172.31.40.23 \
          $DIR/jar5/$SERVCER_JAR  >>$DIR/logs/wbtc/$LOG_NAME  2>&1  &



s_pid=`ps -ef | grep java | grep $SERVCER_JAR |awk '{print $2}'`
send_weixin_v2  "【$date_stamp】【cff/earning-farm】【investment/后端/】【测试环境】【new-plutos2/18.166.174.50】【$branch_v】 分支部署完成, 进程pid：$s_pid , from  部署脚本。 "

